= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 A u t h o r :   Y o u n g w o o k   K i m   ( K o r e a n ) 
 
 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 
 
 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 C o n t a c t :   r u m i a 0 6 0 1 @ g m a i l . c o m 
 
 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 
 
 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 B a s i c   P R O C E S S 
 
 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 
 
 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 - S e t t i n g   f o r   A n i m a t i o n 
 
 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 P r e v i o u s   p r o j e c t   l o o k s   l i k e   a   s i n g l e   i m a g e   i n s t e a d   o f   g a m e .   B e c a u s e   t h e r e   i s   n o   i n p u t   n e i t h e r   p r o c e s s   t o   c o n t r o l   o u t p u t .   O f   c o u r s e ,   c l i c k i n g   e x i t   b u t t o n   o n   w i n d o w   i s   n o t   c o u n t e d   b e c a u s e   i t   i s   j u s t   s h u t t i n g   d o w n   t h e   e n t i r e   p r o g r a m .   F i r s t ,   w e   w i l l   l e t   t e x t    H e l l o   W o r l d !    t o   m o v e   a u t o m a t i c a l l y   ( a n d   n o w   p r o j e c t   w i l l   b e   l o o k s   l i k e   a n   a n i m a t i o n   r a t h e r   t h a n   s i n g l e   i m a g e ) ,   w h i c h   m e a n s   a d d i n g   f i r s t   p r o c e s s i n g   l o g i c   o n   t h i s   p r o j e c t .   H o w   t o   m o v e   t e x t ?   W e   k n o w   t h a t   l o c a t i o n   o f   t e x t   i s   i n i t i a l i z e d   i n   I n i t i a l   s t a t e m e n t .   S o ,   l o c a t i o n   o f   t e x t   s h o u l d   b e   u p d a t e d   i n   A l w a y s   s t a t e m e n t ,   w i t h   a d d i n g   s o m e   v a r i a b l e   t o   p r o c e s s   s o m e t h i n g . 
 
 
 
 
 
 . .   i m a g e : :   B a g i c - P R O C E S S - s o u r c e c o d e . p n g 
 
       : c l a s s :   i n l i n e d - r i g h t 
 
 
 
 . .   c o d e - b l o c k : :   p y t h o n 
 
       : l i n e n o s : 
 
 
 
       i m p o r t   s y s ,   p y g a m e 
 
       p y g a m e . i n i t ( ) 
 
 
 
       s i z e   =   w i d t h ,   h e i g h t   =   2 2 0 ,   1 4 0 
 
       s p e e d   =   [ 2 ,   2 ] 
 
       b l a c k   =   0 ,   0 ,   0 
 
 
 
       s c r e e n   =   p y g a m e . d i s p l a y . s e t _ m o d e ( s i z e ) 
 
 
 
       b a l l   =   p y g a m e . i m a g e . l o a d ( " B a g i c - P R O C E S S - s o u r c e c o d e . p n g " ) 
 
       b a l l r e c t   =   b a l l . g e t _ r e c t ( ) 
 
 
 
       w h i l e   1 : 
 
               f o r   e v e n t   i n   p y g a m e . e v e n t . g e t ( ) : 
 
                       i f   e v e n t . t y p e   = =   p y g a m e . Q U I T :   s y s . e x i t ( ) 
 
 
 
               b a l l r e c t   =   b a l l r e c t . m o v e ( s p e e d ) 
 
               i f   b a l l r e c t . l e f t   <   0   o r   b a l l r e c t . r i g h t   >   w i d t h : 
 
                       s p e e d [ 0 ]   =   - s p e e d [ 0 ] 
 
               i f   b a l l r e c t . t o p   <   0   o r   b a l l r e c t . b o t t o m   >   h e i g h t : 
 
                       s p e e d [ 1 ]   =   - s p e e d [ 1 ] 
 
 
 
               s c r e e n . f i l l ( b l a c k ) 
 
               s c r e e n . b l i t ( b a l l ,   b a l l r e c t ) 
 
               p y g a m e . d i s p l a y . f l i p ( ) 
 
 
 
 
 
 . .   i m a g e : :   B a g i c - P R O C E S S - r e s u l t s c r e e n . p n g 
 
       : c l a s s :   i n l i n e d - r i g h t 
 
 
 
 . .   c o d e - b l o c k : :   p y t h o n 
 
       : l i n e n o s : 
 
 
 
       i m p o r t   s y s ,   p y g a m e 
 
       p y g a m e . i n i t ( ) 
 
 
 
       s i z e   =   w i d t h ,   h e i g h t   =   2 2 0 ,   1 4 0 
 
       s p e e d   =   [ 2 ,   2 ] 
 
       b l a c k   =   0 ,   0 ,   0 
 
 
 
       s c r e e n   =   p y g a m e . d i s p l a y . s e t _ m o d e ( s i z e ) 
 
 
 
       b a l l   =   p y g a m e . i m a g e . l o a d ( " B a g i c - P R O C E S S - r e s u l t s c r e e n . p n g " ) 
 
       b a l l r e c t   =   b a l l . g e t _ r e c t ( ) 
 
 
 
       w h i l e   1 : 
 
               f o r   e v e n t   i n   p y g a m e . e v e n t . g e t ( ) : 
 
                       i f   e v e n t . t y p e   = =   p y g a m e . Q U I T :   s y s . e x i t ( ) 
 
 
 
               b a l l r e c t   =   b a l l r e c t . m o v e ( s p e e d ) 
 
               i f   b a l l r e c t . l e f t   <   0   o r   b a l l r e c t . r i g h t   >   w i d t h : 
 
                       s p e e d [ 0 ]   =   - s p e e d [ 0 ] 
 
               i f   b a l l r e c t . t o p   <   0   o r   b a l l r e c t . b o t t o m   >   h e i g h t : 
 
                       s p e e d [ 1 ]   =   - s p e e d [ 1 ] 
 
 
 
               s c r e e n . f i l l ( b l a c k ) 
 
               s c r e e n . b l i t ( b a l l ,   b a l l r e c t ) 
 
               p y g a m e . d i s p l a y . f l i p ( ) 
 
 
 
 
 
 ( S o u r c e   C o d e   f o r   M o v i n g   W o r l d   P r o j e c t   a n d   i t s   r e s u l t   s c r e e n ) 
 
 
 
 ( N o t   t h e   e n t i r e   s o u r c e   c o d e   o f   M o v i n g   W o r l d   P r o j e c t ,   b u t   p a r t ) 
 
 
 
 ( M o v i n g   W o r l d !   m o v e s   a u t o m a t i c a l l y   j u s t   l i k e   A r k a n o i d   b a l l   o r   D V D   s c r e e n s a v e r . ) 
 
 
 
 
 
 N e w   l i n e   # 1   -   # 5   w e r e   a p p e n d e d   a t   t h e   e n d   o f   I n i t i a l   s t a t e m e n t .   A l s o ,   m u l t i p l e   i f - e l s e   p h a s e s   ( # 6   -   # 9 )   w e r e   i n s e r t e d   a t   t h e   b e g i n n i n g   o f   A l w a y s   s t a t e m e n t ,   w i t h   l i n e   # 1 1   a t   t h e   e n d   o f   a l w a y s   s t a t e m e n t s .   W e   c a n   u n d e r s t a n d   w h a t   c o m m a n d s   o f   # 2   -   # 1 0   d o .   T h e y   j u s t   c h a n g e   v a r i a b l e s   f o r   p o s i t i o n   o f    M o v i n g   W o r l d    w h e n   A l w a y s   s t a t e m e n t   b e i n g   s t a r t e d .   B u t   t h e r e   i s   a   p r o b l e m .   H o w   f a s t   i s    M o v i n g   W o r l d ?    I t   i s   s u r e   t h a t   d i s p l a c e m e n t   o f    M o v i n g   W o r l d    i s   s q r t ( 2 )   ( s i m p l e   P y t h a g o r e a n   e q u a t i o n ) .   B u t   h o w   o f t e n   d i s p l a c e m e n t   o f    M o v i n g   W o r l d    i s   c h a n g e d ?   I t   c a n  t   b e   d e t e r m i n e d   w i t h o u t   c a l c u l a t i n g   t i m e   c o m p l e x i t y   o f   A l w a y s   s t a t e m e n t !   ( B e c a u s e   i t   d e p e n d s   o n   h o w   o f t e n   A l w a y s   s t a t e m e n t   b e i n g   s t a r t e d )   A n d   t i m e   c o m p l e x   w i l l   b e   d i f f e r   t o   c o m p u t e r   t o   c o m p u t e r ,   s o   c a n  t   b e   f i x e d . 
 
 
 
 W e   n e e d   t o   a d d   t h e   c o n c e p t i o n   o f   * * f i x e d   s p e e d * *   i n t o   t h i s   p r o j e c t .   H o w ?   L o o k   a t   # 1   a n d   # 1 1 .   T h e r e   i s   ` ` p y g a m e . t i m e . C l o c k ( ) ` `   o n   I n i t i a l   s t a t e m e n t   a n d   ` ` t i c k ( 6 0 ) ` `   o n   A l w a y s   s t a t e m e n t .   6 0   m e a n s   F P S   ( f r a m e   r a t e   p e r   s e c o n d ) .   W e   k n o w   t h a t   F P S   m e a n s   h o w   o f t e n   d i s p l a y   i s   c h a n g e d   i n   1   s e c o n d .   W h a t   f u n c t i o n   m e a n s   c h a n g e   ( =   u p d a t e )   d i s p l a y   i n   p y g a m e ?   T h a t  s   r i g h t .   P y g a m e . d i s p l a y . u p d a t e ( )   f u n c t i o n .   S o ,   F P S   m e a n s   h o w   o f t e n   A l w a y s   s t a t e m e n t   b e i n g   e x e c u t e d   i n   1   s e c o n d .   B e c a u s e   t h e r e   i s   1   P y g a m e . d i s p l a y . u p d a t e ( )   f u n c t i o n   i n   1   a l w a y s   s t a t e m e n t s .   ( S o ,   F P S   m e a n s   * * s e l e c t i v e   d e l a y * *   a c c o r d i n g   t o   c u r r e n t   p r o g r a m  s   p r o c e s s   s p e e d ,   * * n o t   s e l e c t i v e   a c c e l e r a t i o n * * ,   s o   F P S   c a n n o t   w o r k   i f   F P S   i s   t o o   h i g h . )   I f   w e   l e t   f p s ( =   * * t i m e * * )   t o   b e   f i x e d   i n   t h i s   p r o j e c t ,   w e   c a n   c h a n g e   * * v e l o c i t y * *   o f   c e r t a i n   g a m e   o b j e c t   b y   f i n d i n g   a p p r o p r i a t e   v a l u e   f o r   * * d i s p l a c e m e n t * * .   p y g a m e . t i m e . C l o c k ( )   i s   n e e d e d   t o   f i x   t h e   s p e e d   o f   p r o j e c t   b e f o r e   g a m e   s t a r t e d .   N o t i c e   t h a t   t i c k   f u n c t i o n   h a s   t o   b e   c a l l e d   w h e n   P y g a m e . d i s p l a y . u p d a t e ( )   i s   c a l l e d .   B e c a u s e   t i c k   c o u n t s   t h e   n u m b e r   o f   u p d a t e   f u n c t i o n .   I t   i s   o n e   o f   t h e   e x c e p t i o n   o f   f u n c t i o n   t h a t   c a n   b e   e x e c u t e d   a f t e r   P y g a m e . d i s p l a y . u p d a t e ( ) . 
 
 
 
 O k a y ,   w e   l e a r n   t h a t    F i x i n g   t i m e    i s   n e e d e d   w h e n   s c r e e n   i s   u p d a t e d .   E v e r y   s c r e e n   o f   d y n a m i c   g a m e   i s   f r e q u e n t l y   c h a n g e d   u n l e s s   i t   i s   s t a t i c   g a m e .   S o ,   w e   h a v e   t o   k n o w   t h a t .   H o w e v e r ,   t h i s   p r o j e c t   i s n  t   l o o k   l i k e   a   g a m e   b e c a u s e   i t s   r e s u l t   c a n   b e   a n t i c i p a t e d   e a s i l y   ( t h e r e   i s   n o   i n p u t   t o   c h a n g e   r e s u l t )   N o w ,   i n p u t   l o g i c   w i l l   b e   i n s e r t e d . 
 
 
 
 
 
 < R e f e r e n c e   C o d e >   : : 
 
 
 
         i m p o r t   p y g a m e ,   s y s 
 
         f r o m   p y g a m e . l o c a l s   i m p o r t * 
 
 
 
         w h i t e   =   ( 2 5 5 , 2 5 5 , 2 5 5 ) 
 
         r e d   =   ( 2 5 5 , 0 , 0 ) 
 
         g r e e n   =   ( 0 , 2 5 5 , 0 ) 
 
         p y g a m e . i n i t ( ) 
 
         p y g a m e . d i s p l a y . s e t _ c a p t i o n ( " M o v i n g   W o r l d   P r o j e c t " )   
 
         m y S c r e e n   =   p y g a m e . d i s p l a y . s e t _ m o d e ( ( 6 4 0 ,   4 8 0 ) ) 
 
         m y T e x t F o n t   =   p y g a m e . f o n t . F o n t ( " H o o n W h i t e c a t R . t t f " ,   3 2 ) 
 
         m y T e x t   =   m y T e x t F o n t . r e n d e r ( " M o v i n g   W o r l d ! " ,   T r u e ,   r e d ,   g r e e n )   
 
         m y T e x t A r e a   =   m y T e x t . g e t _ r e c t ( ) 
 
         m y T e x t A r e a . c e n t e r   =   ( 3 2 0 ,   2 4 0 ) 
 
         f p s C l o c k   =   p y g a m e . t i m e . C l o c k ( )   # 1 
 
         x   =   0   # 2 
 
         y   =   0   # 3 
 
         m o v e R i g h t   =   1   # 4 
 
         m o v e U p =   1   # 5 
 
 
 
         w h i l e   T r u e : 
 
                 i f   ( m o v e R i g h t   = =   1 ) :   # 6 
 
                         x   =   x   +   1 
 
                         i f   ( x   > =   3 2 0   -   7 5 ) : 
 
                                 m o v e R i g h t   =   0 
 
                 e l i f   ( m o v e R i g h t   = =   0 ) :   # 7 
 
                         x   =   x   -   1 
 
                         i f   ( x   < =   - 3 2 0   +   7 5 ) : 
 
                                 m o v e R i g h t   =   1 
 
 
 
                 i f   ( m o v e U p   = =   1 ) :   # 8 
 
                         y   =   y   +   1 
 
                         i f   ( y   > =   2 4 0   -   1 5 ) : 
 
                                 m o v e U p   =   0 
 
                 e l i f   ( m o v e U p   = =   0 ) :   # 9 
 
                         y   =   y   -   1 
 
                         i f   ( y   < =   - 2 4 0   +   1 5 ) : 
 
                                 m o v e U p   =   1 
 
 
 
 
 
 
 
         m y T e x t A r e a . c e n t e r   =   ( 3 2 0   +   x ,   2 4 0   +   y )   # 1 0 
 
         
 
         m y S c r e e n . f i l l ( w h i t e ) 
 
         m y S c r e e n . b l i t ( m y T e x t ,   m y T e x t A r e a ) 
 
 
 
         f o r   e v e n t   i n   p y g a m e . e v e n t . g e t ( ) : 
 
                 i f   e v e n t . t y p e   = =   Q U I T : 
 
                         p y g a m e . q u i t ( ) 
 
                         s y s . e x i t ( ) 
 
 
 
         p y g a m e . d i s p l a y . u p d a t e ( ) 
 
         f p s C l o c k . t i c k ( 6 0 )   # 1 1 
 
 
 
 